//下列三行代码,为刚需,此提供了下列所有代码的入口
'use strict';
 
goog.provide('Blockly.Blocks.SpriteBot');//注意脚本类别及路径名称
 
goog.require('Blockly.Blocks');

const mediaDirPath = path.join(document.currentScript.src, '../../media/');
// ---OLED模块图形配置---
var POSE_LIST =[["前进", "1"], ["后退", "2"], ["左转", "3"], ["右转", "4"],["停止", "5"], ["俯卧撑", "6"],  ["战斗", "7"]];
var DISTANCE_LIST = [ ["6cm", "6"], ["7cm", "7"], ["8cm", "8"], ["9cm", "9"], ["10cm", "10"], ["11cm", "11"], ["12cm", "12"], ["13cm", "13"], ["14cm", "14"], ["15cm", "15"], ["16cm", "16"], ["17cm", "17"], ["18cm", "18"], ["19cm", "19"]];


var yfrobotColor_input = '#eb984e';  //输入模块-传感器
Blockly.Blocks['Demo1'] = {
  init: function () {
      this.appendDummyInput()
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot1.png", 50, 50, "*"))
          .appendField("样例1: ");
      this.appendDummyInput()
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/demo1.png", 413, 361, "*"));

      this.setColour("#C0C0C0");
      this.setInputsInline(true);
      this.setPreviousStatement(false, null);
      this.setNextStatement(false, null);
  }
};
//include模块
Blockly.Blocks.SpriteBot_include = {
  init: function() {
    this.setColour(120);//模块图形颜色
    this.appendDummyInput("")//此行代码刚需,为模块创建提供入口
        .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot1.png", 32, 32))
        .appendField("引入蜘蛛机器人库 ") //代码块上的文字内容
    this.setPreviousStatement(true);//是否可以与上一模块连接
    this.setNextStatement(true);//是否可以与下一模块连接
  }
};
 
//配置构造函数模块
Blockly.Blocks.config = {
  init: function() {
    this.setColour(120);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/chat_more.png", 32, 22))
    .appendField("创建一个蜘蛛机器人对象:");
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(false);//是否开启模块单行显示(true为单行,false为多行)
  }
};
 

Blockly.Blocks.initSpriteBot = {
  init: function() {
    this.setColour(160);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/wifi_logo.png", 30, 30))
    .appendField("初始化蜘蛛机器人")
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};

Blockly.Blocks.initController = {
  init: function() {
    this.setColour(190);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/control_icon_3.png", 30, 30))
    .appendField("初始化遥控器")
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};
Blockly.Blocks.move_stop = {
  init: function () {
      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot3.png", 32, 32))
          .appendField('停止');
          
      this.setInputsInline(true);
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour("#A06C78");
  }
};

Blockly.Blocks.move_front = {
  init: function () {
      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot3.png", 32, 32))
          .appendField('前进');
          
      this.setInputsInline(true);
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour("#A06C78");
  }
};

Blockly.Blocks.move_back = {
  init: function () {
      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot3.png", 32, 32))
          .appendField('后退');
          
      this.setInputsInline(true);
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour("#A06C78");
  }
};

Blockly.Blocks.move_left = {
  init: function () {
      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot3.png", 32, 32))
          .appendField('左转');
          
      this.setInputsInline(true);
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour("#A06C78");
  }
};

Blockly.Blocks.move_right = {
  init: function () {
      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot3.png", 32, 32))
          .appendField('右转');
          
      this.setInputsInline(true);
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour("#A06C78");
  }
};

Blockly.Blocks.pose_control_list = {
    init: function () {
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/bot2.png", 32, 32))
            .appendField('动作控制')
            .appendField("类型：")
            .appendField(new Blockly.FieldDropdown(POSE_LIST), "cmd");
            
            
        this.appendValueInput('count')
            .setCheck(Number)
            .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/change.png", 32, 32))
            .appendField('执行时间长度（秒）');

        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour("#E06C78");
    }
};
Blockly.Blocks.Distance = {
  init: function () {
     this.setColour(yfrobotColor_input);

      this.appendDummyInput("")
          .appendField(new Blockly.FieldImage(mediaDirPath + "/SpriteBot/ultrasonic_04.png", 32, 32))
          .appendField('超声波触发');
      this.appendValueInput('count',Number)
          .appendField('距离(5~20cm)：')
          .setCheck(Number);
          
      this.setInputsInline(true);
      this.setOutput(true, Number);
      this.setTooltip('读取超声波的返回值（有效测距范围为：5~20cm）');

  }
};

  


